Optical orientation is a highly efficient tool for the generation of nonequilibrium spin polarization in semiconductors. Combined with spin-polarized transport it offers new functionalities for conventional electronic devices, such as pn junction bipolar diodes or transistors. In nominally nonmagnetic junctions optical orientation can provide a source for spin capacitance--the bias-dependent nonequilibrium spin accumulation--or for spin-polarized current in bipolar spin-polarized solar cells. In magnetic junctions, the nonequilibrium spin polarization generated by spin orientation in a proximity of an equilibrium magnetization gives rise to the spin-voltaic effect (a realization of the Silsbee-Johnson coupling), enabling efficient control of electrical properties such as the I-V characteristics of the junctions by magnetic and optical fields. This article reviews the main results of investigations of spin-polarized and magnetic pn junctions, from spin capacitance to the spin-voltaic effect.