public string Register(string login, string password, string name, string email) { if (string.IsNullOrEmpty(login)) { return("Не заполнено имя пользователя"); } IParameterCollection Params = new ParameterCollection(); Params.Add("@login", login); SqlManager M = new DersaAnonimousSqlManager(); int checkresult = M.ExecuteSPWithResult("DERSA_USER$Exists", false, Params); if (checkresult > 0) { return("Пользователь с таким логином уже зарегистрирован"); } Params.Add("@email", Cryptor.Encrypt(email, Util.GetDefaultPassword())); checkresult = M.ExecuteSPWithResult("DERSA_USER$Exists", false, Params); if (checkresult > 0) { return("Пользователь с таким email уже зарегистрирован"); } try { Token(login, email); System.Data.DataTable T = M.ExecuteSPWithParams("DERSA_USER$Register", new object[] { login, password, Cryptor.Encrypt(email, Util.GetDefaultPassword()), name }); return(""); } catch (Exception exc) { return(exc.Message); } }
public static string AuthorizeUser(string user_name = "", string password = "") { string result = "Unknown user name or password."; try { IParameterCollection Params = new ParameterCollection(); Params.Add("@login", user_name); Params.Add("@password", password); SqlManager M = new DersaAnonimousSqlManager(); int checkresult = M.ExecuteSPWithResult("DERSA_USER$CanAuthorize", false, Params); if (checkresult == (int)DersaUserStatus.active) { IAuthenticationManager authenticationManager = HttpContext.Current.GetOwinContext().Authentication; authenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie); var User = new UserProvider(user_name); System.Security.Claims.ClaimsIdentity identity = new System.Security.Claims.ClaimsIdentity(User.Identity, null, "ApplicationCookie", null, null); authenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = false }, identity); return(""); } switch (checkresult) { case (int)DersaUserStatus.registered: result = "Your registration is not completed."; break; } } catch { throw; } return(result); }
public string Activate(string token) { string sresult = Cryptor.Decrypt(token, Util.GetDefaultPassword()); ActivateStruct S = JsonConvert.DeserializeObject(sresult, typeof(ActivateStruct)) as ActivateStruct; IParameterCollection Params = new ParameterCollection(); Params.Add("@id", S.userid); Params.Add("@login", S.username); Params.Add("@password", Util.GetPassword(S.username)); SqlManager M = new DersaAnonimousSqlManager(); int checkresult = M.ExecuteSPWithResult("DERSA_USER$Activate", false, Params); return(S.username); }