Esempio n. 1
0
        public async Task <IActionResult> Join([FromBody] RequestUserJoinModel model)
        {
            // check format
            if (model.Username.IsValidUsername() == false)
            {
                return(Responsed(ErrorCode.InvalidUserName));
            }

            if (model.EMail.IsValidEmailAddress() == false)
            {
                return(Responsed(ErrorCode.InvalidEMail));
            }

            // check account
            AccountBasicData basicData = new AccountBasicData();

            if (await basicData.FromDBByUserNameAsync(model.Username))
            {
                return(Responsed(ErrorCode.ExistUserName));
            }

            if (await basicData.FromDBByEmailAsync(model.EMail))
            {
                return(Responsed(ErrorCode.ExistEMail));
            }

            // check verify code
            ErrorCode emailVerifyResult = CheckEMailVerifyCode(model.EMail, model.VerifyCode, false);

            if (emailVerifyResult != ErrorCode.Success)
            {
                return(Responsed(emailVerifyResult));
            }

            // insert database
            DBQuery_Account_Insert query = new DBQuery_Account_Insert();

            basicData = query.IN.BasicData;
            basicData.AccountDBKey = DBKeyGenerator.NewAccountDBKey;
            basicData.EMail        = model.EMail;
            basicData.CreateTime   = DateTime.UtcNow;
            basicData.Username     = model.Username;
            basicData.Password     = PasswordUtility.HashPassword(model.Password);

            if (await DBThread.Instance.ReqQueryAsync(query) == false)
            {
                return(Responsed(ErrorCode.DatabaseError));
            }

            // response
            ResponseUserJoinModel responseData = new ResponseUserJoinModel();

            responseData.EMail      = model.EMail;
            responseData.CreateTime = basicData.CreateTime;
            responseData.Username   = model.Username;

            return(Success(responseData));
        }
Esempio n. 2
0
        // 로그인 처리
        private async Task <ErrorCode> ProcessLoginAsync(string emailOrUserName, string password, int timeZoneOffsetFromUTC)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(ErrorCode.AlreadyLoggedin);
            }

            if (emailOrUserName.Length < 2)
            {
                return(ErrorCode.InvalidUserName);
            }

            bool isEMail = emailOrUserName.Contains('@');

            AccountBasicData basicData = new AccountBasicData();

            if (isEMail)
            {
                if (await basicData.FromDBByEmailAsync(emailOrUserName) == false)
                {
                    return(ErrorCode.InvalidEMail);
                }
            }
            else
            {
                if (await basicData.FromDBByUserNameAsync(emailOrUserName) == false)
                {
                    return(ErrorCode.InvalidUserName);
                }
            }

            if (PasswordUtility.VerifyPassword(password, basicData.Password) == false)
            {
                return(ErrorCode.InvalidPassword);
            }

            var claims = new List <Claim>();

            claims.Add(new Claim(ClaimTypes.SerialNumber, basicData.AccountDBKey.ToString()));
            claims.Add(new Claim(ClaimTypes.GivenName, basicData.GivenName));
            claims.Add(new Claim(ClaimTypes.Surname, basicData.SurName));
            claims.Add(new Claim(ClaimTypes.Name, basicData.Username));
            claims.Add(new Claim(ClaimTypes.Email, basicData.EMail));
            claims.Add(new Claim("TimeZoneOffset", TimeSpan.FromMinutes(timeZoneOffsetFromUTC).ToString()));

            var userIdentity = new ClaimsIdentity(claims, "login");

            ClaimsPrincipal principal = new ClaimsPrincipal(userIdentity);
            await HttpContext.SignInAsync(principal);

            return(ErrorCode.Success);
        }
Esempio n. 3
0
        public async Task <IActionResult> JoinVerifyEMail([FromBody] RequestUserJoinVerifyEMailModel model)
        {
            // check format
            if (model.EMail.IsValidEmailAddress() == false)
            {
                return(Responsed(ErrorCode.InvalidEMail));
            }

            // check account
            AccountBasicData basicData = new AccountBasicData();

            if (await basicData.FromDBByEmailAsync(model.EMail))
            {
                return(Responsed(ErrorCode.ExistEMail));
            }

            return(Success());
        }
Esempio n. 4
0
        public async Task <IActionResult> ResetPassword([FromBody] RequestUserResetPasswordModel model)
        {
            // check account
            AccountBasicData basicData = new AccountBasicData();

            if (await basicData.FromDBByEmailAsync(model.EMail) == false)
            {
                return(Responsed(ErrorCode.InvalidEMail));
            }

            string newPassword = DBKeyGenerator.NewVerifyCode;

            basicData.Password = PasswordUtility.HashPassword(newPassword);

            var query = new DBQuery_Account_Update_Password();

            query.IN.AccountDBKey = basicData.AccountDBKey;
            query.IN.Password     = basicData.Password;

            if (await DBThread.Instance.ReqQueryAsync(query) == false)
            {
                return(Responsed(ErrorCode.DatabaseError));
            }


            // 이메일 발송
            StringBuilder msg = new StringBuilder(1024);

            msg.AppendLine(string.Format($"Hello. {basicData.Username}"));
            msg.AppendLine(string.Format($"Reseted your password."));
            msg.AppendLine();
            msg.AppendLine(string.Format($"Your temp password : {newPassword}"));

            await WebServiceUtility.SendEMailAsync("[Hena Platform] Reseted your password.", msg.ToString(), false, model.EMail);


            return(Success());
        }
Esempio n. 5
0
        public async Task <IActionResult> SendVerifyEMail([FromBody] RequestUserSendVerifyEMailModel model)
        {
            // check account
            AccountBasicData basicData = new AccountBasicData();

            if (await basicData.FromDBByUserNameAsync(model.Username))
            {
                return(Responsed(ErrorCode.ExistUserName));
            }

            if (await basicData.FromDBByEmailAsync(model.EMail))
            {
                return(Responsed(ErrorCode.ExistEMail));
            }

            // generate verify data
            var verifyData = VerifyDataManager.Instance.NewVerifyData(TimeSpan.FromMinutes(3)
                                                                      , TimeSpan.FromHours(1), true, model);

            // 이메일 발송
            StringBuilder msg = new StringBuilder(1024);

            msg.AppendLine(string.Format($"Hello. {model.Username}"));
            msg.AppendLine(string.Format($"Please enter your verification code below and complete verification."));
            msg.AppendLine();
            msg.AppendLine(string.Format($"CODE : {verifyData.VerifyCode}"));

            await WebServiceUtility.SendEMailAsync("[Hena Platform] Signup verification code.", msg.ToString(), false, model.EMail);

            // 메일 발송
            ResponseUserSendVerifyEMailModel responseData = new ResponseUserSendVerifyEMailModel();

            responseData.EMail    = model.EMail;
            responseData.Username = model.Username;

            return(Success(responseData));
        }